<template>
    <div class="app-container app-height">
        <div class="header-content">
            <h3 class="code-title">统计规则列表</h3>
            <el-button
                type="primary"
                size="small"
                @click="createStatisticsHnadle"
                >新建统计</el-button
            >
        </div>
        <!-- <el-table
            v-loading="loading"
            :data="DataList"
            border
            :max-height="mapHeight"
        > -->
        <el-table
            v-loading="loading"
            :data="DataList"
            border
            :height="mapHeight"
        >
            <el-table-column
                label="序号"
                align="center"
                type="index"
                width="85"
            ></el-table-column>
            <el-table-column
                label="统计名称"
                align="center"
                prop="jobName"
                width="199"
                :show-overflow-tooltip="true"
            >
                <!-- <template slot-scope="scope">
                    <a
                        href="javascript:;"
                        style="color:#409eff;"
                        @click="handleGoto(scope.row)"
                        >{{ scope.row.tableName }}</a
                    >
                </template> -->
            </el-table-column>
            <el-table-column
                label="统计周期"
                align="center"
                width="199"
                prop="statisticsPeriodName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="统计时间"
                align="center"
                width="199"
                prop="statisticsTime"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="统计的表单数量"
                align="center"
                width="199"
                prop="statisticalTableCount"
            />
            <el-table-column
                label="创建时间"
                align="center"
                prop="createTime"
                width="199"
            />
            <el-table-column
                label="创建人"
                align="center"
                prop="createBy"
                width="199"
            />
            <el-table-column
                label="最后一次统计时间"
                align="center"
                prop="finallyStatisticalData"
                width="199"
            />
            <el-table-column
                label="状态"
                align="center"
                prop="statisticalStatus"
                width="199"
            >
                <template slot-scope="scope">
                    <span
                        v-text="
                            scope.row.status == '0'
                                ? '正常'
                                : scope.row.status == '1'
                                ? '暂停'
                                : ''
                        "
                    ></span>
                </template>
            </el-table-column>
            <el-table-column label="下载统计详情" align="center" width="100">
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        size="mini"
                        @click="downloadHandle(scope.row)"
                        >下载</el-button
                    >
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="199">
                <template slot-scope="scope">
                    <template v-if="scope.row.hasPermisson === true || true">
                        <el-popconfirm
                            v-if="scope.row.status == '0'"
                            title="确定停止吗？"
                            @confirm="stop(scope.row)"
                            style="margin-right:10px"
                        >
                            <p
                                slot="reference"
                                class="simple-btn danger-simple-btn"
                            >
                                停止
                            </p>
                        </el-popconfirm>
                        <el-popconfirm
                            v-else
                            title="确定开启吗？"
                            @confirm="start(scope.row)"
                            style="margin-right:10px"
                        >
                            <p
                                slot="reference"
                                class="simple-btn primary-simple-btn"
                            >
                                开启
                            </p>
                        </el-popconfirm>
                        <p
                            class="simple-btn primary-simple-btn"
                            @click="edit(scope.row)"
                        >
                            修改
                        </p>
                    </template>
                    <p
                        class="simple-btn primary-simple-btn"
                        @click="viewDetail(scope.row)"
                    >
                        查看
                    </p>
                    <p
                        class="simple-btn primary-simple-btn"
                        @click="manualStatistics(scope.row)"
                    >
                        手动统计
                    </p>
                </template>
            </el-table-column>
        </el-table>
        <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="requestList"
        />
    </div>
</template>
<script>
import {
    getStatisticsRuleList,
    downLoadStatisticsRuleList,
    editStatisticsRuleStatus,
    openStatisticsRule,
    stopStatisticsRule,
    manualStatistics
} from "@/api/dataManagement/dataMonitor/dataStatistics";
import { groupUserList } from "@/api/dataManagement/system/group";
import { getHeight } from "@/utils/zkComm";
export default {
    name: "statistics",
    data() {
        return {
            // 遮罩层
            loading: false,
            // 用户表格数据
            morehandleValue: "",
            total: 0,
            mapHeight: undefined,
            DataList: [
                // {
                //     tableName: "测试table_log",
                //     tableAlias: "table_log",
                //     deptName: "数据仓库（CDM）>商保部门（SHB）",
                //     safeLevel: "1",
                //     totalRow: 1234421,
                //     updateTime: "2021-2-17",
                //     concern: true,
                //     id: 226,
                //     dirId: 20
                // },
                // {
                //     tableName: "测试table_log",
                //     tableAlias: "table_log",
                //     deptName: "数据仓库（CDM）>商保部门（SHB）",
                //     safeLevel: "1",
                //     totalRow: 1234421,
                //     updateTime: "2021-2-17",
                //     concern: false,
                //     id: 226,
                //     dirId: 20
                // }
            ],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 30
                // tableName: undefined,
                // groupId: "",
                // status: undefined
            },
            groupList: [],
            statusList: [
                {
                    label: "驳回",
                    value: "0"
                },
                {
                    label: "通过",
                    value: "1"
                },
                {
                    label: "申请中",
                    value: "2"
                },
                {
                    label: "已撤销",
                    value: "3"
                }
            ]
        };
    },
    created() {
        // this.getlistGroup();
        this.requestList();
    },
    mounted() {
        this.mapHeight = getHeight(true);
        console.log(this.mapHeight);
    },
    methods: {
        requestList(fresh = false) {
            if (fresh === true) {
                this.queryParams.pageNum = 1;
            }
            this.loading = true;
            getStatisticsRuleList(this.queryParams).then(res => {
                this.DataList = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        createStatisticsHnadle() {
            this.$router.push("/DMS/monitoring/statistics/details");
        },
        stop(row) {
            stopStatisticsRule(row.id).then(res => {
                if (res.code !== 200) {
                    this.$message.error("修改失败");
                    return;
                }
                this.$message.success("修改成功");
                this.requestList();
            });
        },
        start(row) {
            openStatisticsRule(row.id).then(res => {
                if (res.code !== 200) {
                    this.$message.error("修改失败");
                    return;
                }
                this.$message.success("修改成功");
                this.requestList();
            });
        },
        // 废弃
        chageStuts(parmas) {
            editStatisticsRuleStatus(parmas).then(res => {
                if (res.code !== 200) {
                    this.$message.error("修改失败");
                    return;
                }
                this.$message.success("修改成功");
                this.requestList();
            });
        },
        edit(row) {
            // console.log("row:",row)
            this.$router.push({
                path: "/DMS/monitoring/statistics/details",
                query: {
                    id: row.id,
                    isEdit: true
                }
            });
        },
        viewDetail(row) {
            this.$router.push({
                path: "/DMS/monitoring/statistics/details",
                query: {
                    id: row.id
                }
            });
        },
        manualStatistics(row) {
            manualStatistics(row.id)
                .then(res => {
                    if (res.code !== 200) {
                        this.$message.error("修改失败");
                        return;
                    }
                    this.$message.success("修改成功");
                    this.requestList();
                })
                .catch(err => {
                    this.$message.error("修改失败");
                });
        },
        handleDelete() {},
        // 下载
        downloadHandle(row) {
            downLoadStatisticsRuleList(row.id).then(res => {
                if (res.code === 200) {
                    this.download(res.msg);
                } else {
                    this.$message.error("下载失败");
                }
            });
        },
        //获取分组
        getlistGroup() {
            groupUserList().then(res => {
                this.groupList = res.data;
                this.groupList.unshift({ groupName: "本人", groupId: "" });
            });
        },
        handleGoto(row) {
            this.$router.push("/DMS/myData/logRecord/details?id=" + row.id);
        },
        uploadBtn() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 30,
                tableName: undefined,
                groupId: "",
                status: undefined
            };
            // this.requestList(true);
        },
        searchBtn() {
            // this.requestList(true);
        }
    }
};
</script>

<style lang="scss" scoped>
/****
 reset element style
.

 */
.header-content {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    .code-title {
        border-left: 4px solid #1183f8;
        padding-left: 10px;
        line-height: 20px;
        height: 20px;
        font-weight: 400;
        font-size: 18px;
        margin: 0 10px 0 0;
        color: #606266;
    }
    ::v-deep .el-button--small {
        height: 30px;
    }
}
.el-col-3 {
    width: 70px;
}
.el-col-2 {
    width: 96px;
    margin-right: 10px;
}
/****
 reset element style
.

 */
.app-container {
    padding: 20px;
    ::v-deep {
        .el-button--mini:hover {
            text-decoration: underline;
        }
    }
}
.operation {
    height: 43px;
    line-height: 43px;
    margin-bottom: 20px;
    .search-select-parent {
        width: 320px;
    }
    .concern {
        margin-left: 10px;
    }
    .associa-select,
    .el-form-item {
        margin-right: 10px;
    }
    .search-btn {
        margin-right: 0px !important;
    }
}
.concern-icon {
    &:hover {
        cursor: pointer;
    }
}
</style>
